package com.piece.core.resource.config;

import com.piece.core.resource.support.CustomResourceServerTokenServices;
import com.piece.core.resource.support.CustomTokenExtractor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.oauth2.provider.authentication.TokenExtractor;
import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices;
import org.springframework.security.oauth2.provider.token.TokenStore;

public class CustomResourceServerHandlerConfig {

    @Autowired(required = false)
    private TokenStore tokenStore;

    @Bean
    public TokenExtractor tokenExtractor() {
        return new CustomTokenExtractor();
    }

    @Bean("resourceServerTokenServices")
    public ResourceServerTokenServices resourceServerTokenServices() {
        return new CustomResourceServerTokenServices(tokenStore);
    }
}
